import { Body, Controller, Get, Post, Query } from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { Public } from '@/decorator/public';
import { UserService } from './user.service';
import { RegisterUserDto } from './dto/register-user.dto';
import { LoginUserDto } from './dto/login-user.dto';
import { SaveAddressDto } from './dto/save-address.dto';
import { WechatLoginDto } from './dto/wechat-login.dto';

@Controller('user')
@ApiTags('用户模块')
export class UserController {
  constructor(private readonly userService: UserService) { }

  @Get('detail')
  @ApiOperation({ summary: '用户详情' })
  async Detail(@Query('id') id: string) {
    return await this.userService.Detail(id);
  }

  @Get('list')
  @ApiOperation({ summary: '获取用户列表' })
  async getUserList() {
    return await this.userService.getUserList();
  }

  // @Patch()
  // @ApiOperation({ summary: '更新用户' })
  // async Update(@Body() userUpdateDto: UpdateUserDto) {
  //   await this.userService.Update(userUpdateDto);
  // }

  @Public()
  @Get('phone/by-phone-code')
  @ApiOperation({ summary: '根据phoneCode获取用户手机号' })
  async QueryPhoneByPhoneCode(@Query('code') code: string) {
    return await this.userService.QueryPhoneByPhoneCode(code);
  }

  @Public()
  @Get('phone/by-login-code')
  @ApiOperation({ summary: '根据loginCode获取用户手机号' })
  async QueryPhoneByLoginCode(@Query('code') code: string): Promise<string> {
    return await this.userService.QueryPhoneByLoginCode(code);
  }

  @Public()
  @Post('register-login')
  @ApiOperation({ summary: '用户注册并登录' })
  async RegisterAndLogin(@Body() registerUserDto: RegisterUserDto) {
    return await this.userService.RegisterAndLogin(registerUserDto);
  }

  @Public()
  @Post('login')
  @ApiOperation({ summary: '用户登录' })
  async Login(@Body() loginUserDto: LoginUserDto) {
    return await this.userService.Login(loginUserDto);
  }

  @Public()
  @Post('save-address')
  @ApiOperation({ summary: '保存用户地址' })
  async saveAddress(@Body() saveAddressDto: SaveAddressDto) {
    return await this.userService.saveAddress(saveAddressDto);
  }

  @Public()
  @Post('wechat-login')
  @ApiOperation({ summary: '微信一键登录' })
  async wechatLogin(@Body() wechatLoginDto: WechatLoginDto) {
    return await this.userService.wechatLogin(wechatLoginDto);
  }
}
